/*
 * @Author: lizhijie429
 * @Date: 2021-09-15 18:51:02
 * @LastEditors: lizhijie429
 * @LastEditTime: 2021-09-15 19:20:40
 * @Description:
 */

/* 把扁平数据转成树形数据 */
export function treeData(source, levelParentId) {
  let cloneData = JSON.parse(JSON.stringify(source));
  return cloneData.filter(father => {
    let childrenArr = cloneData.filter(child => father["_id"] === child["parentId"]);
    console.log("branchArr", childrenArr);
    childrenArr.length > 0 ? (father["children"] = childrenArr) : (father["children"] = []);
    return father["_id"] === levelParentId;
  });
}
